package com.atguigu.classroom.vod.service.impl;

import com.atguigu.classroom.model.vod.VideoVisitor;
import com.atguigu.classroom.vo.vod.VideoVisitorCountVo;
import com.atguigu.classroom.vod.mapper.VideoVisitorMapper;
import com.atguigu.classroom.vod.service.VideoVisitorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 视频来访者记录表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2022-07-12
 */
@Service
public class VideoVisitorServiceImpl extends ServiceImpl<VideoVisitorMapper, VideoVisitor> implements VideoVisitorService {

    @Autowired
    private VideoVisitorMapper videoVisitorMapper;
    @Override
    public Map<String, Object> getCount(Long courseId, String startDate, String endDate) {
        List<VideoVisitorCountVo> videoVisitorCountVoList=videoVisitorMapper.findCount(courseId,startDate,endDate);
        //创建两个list集合，一个代表日期，一个代表日期对应的数量；
        Map<String, Object> map=new HashMap<>();
        List<String> dateList=new ArrayList<>(videoVisitorCountVoList.size());
        List<String> countList=new ArrayList<>(videoVisitorCountVoList.size());
        videoVisitorCountVoList.stream().map(v->{
            dateList.add(v.getJoinTime());
            countList.add(String.valueOf(v.getUserCount()));
            return null;
        }).collect(Collectors.toList());
        map.put("xData",dateList);
        map.put("yData",countList);
        return map;
    }
}
